package org.example;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class test17 {
    public static void main(String[] args) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        // 使用int和Integer示例
        int num = 0;
        Integer NUM = 0;

        //进行序列化为json字符串
        String jsonint = objectMapper.writeValueAsString(num);
        System.out.println("jsonint:  " + jsonint);

        String jsonInteger = objectMapper.writeValueAsString(NUM);
        System.out.println("jsonint:  " + jsonInteger);

        System.out.println("-------------");

        // 反序列化为整数
        int number = objectMapper.readValue(jsonint, int.class);
        System.out.println("number:  " + number);

        Integer NUMBER = objectMapper.readValue(jsonInteger, Integer.class);
        System.out.println("NUMBER  " + NUMBER);

        System.out.println("------boolean-------");
        // 序列化为JSON字符串
        String jsonBoolean = objectMapper.writeValueAsString(true);
        System.out.println("JSON (boolean): " + jsonBoolean);

        // 反序列化为布尔值
        boolean deserializedBoolean = objectMapper.readValue(jsonBoolean, boolean.class);
        System.out.println("Boolean: " + deserializedBoolean);

        System.out.println("-------------");

        // 使用 Boolean 示例
        // 序列化为 JSON 字符串
        String jsonBooleanObject = objectMapper.writeValueAsString(Boolean.TRUE);
        System.out.println("JSON (Boolean): " + jsonBooleanObject);

        // 反序列化为布尔对象
        Boolean deserializedBooleanObject = objectMapper.readValue(jsonBooleanObject, Boolean.class);
        System.out.println("Boolean Object: " + deserializedBooleanObject);
    }
}
